"""
@author: 江同学呀
@file: dense_vector_field.py
@date: 2024/7/28 18:35
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/dense-vector.html

    Records dense vectors of float values.
    记录浮点值的密集向量。
"""
from abc import ABC
from typing import Type, Union, Dict, List

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField
from espc.orm.model.mapping.field.field_attribute import DimsAttribute
from espc.utils.build_add_attr import build_add_attr


class DenseVectorField(_BaseField, DimsAttribute, ABC):
    """
    密集向量场 字段
    """
    _field_type: str = "dense_vector"

    def __init__(
            self, field_name: str = None, value: List[float] = None, default: List[float] = None, dims: int = None
    ):
        super().__init__(field_name=field_name, value=value, default=default, dims=dims)
        return

    def __get__(self, instance: _Base, owner: Type["DenseVectorField"]) -> Union["DenseVectorField", List[float]]:
        return super(DenseVectorField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: List[float]):
        super(DenseVectorField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> List[float]:
        return self._value

    @value.setter
    def value(self, value: List[float]):
        self._value: List[float] = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping




